package com.geostar.constructionland.analyse.service.dataquery.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.geostar.constructionland.analyse.entity.alyresult.AlyResultZbq;
import com.geostar.constructionland.analyse.entity.model.AnalyseQueryModel;
import com.geostar.constructionland.analyse.entity.vo.*;
import com.geostar.constructionland.analyse.mapper.sptalyresult.AlyResultZbqMapper;
import com.geostar.constructionland.analyse.mapper.statistics.SticCszbYjjbntMapper;
import com.geostar.constructionland.analyse.mapper.statistics.SticTzhdlgdMapper;
import com.geostar.constructionland.analyse.mapper.statistics.SticZbqfxMapper;
import com.geostar.constructionland.analyse.service.dataquery.AnalyseDataService;
import com.geostar.constructionland.common.global.ConstAnalyseType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Field;
import java.util.LinkedList;
import java.util.List;

@Service
public class AnalyseDataServiceImpl implements AnalyseDataService {

    @Autowired
    AlyResultZbqMapper zbqMapper;

    @Autowired
    SticCszbYjjbntMapper sticCszbYjjbntMapper;

    @Autowired
    SticTzhdlgdMapper sticTzhdlgdMapper;

    @Autowired
    SticZbqfxMapper sticZbqfxMapper;

    @Override
    public List getAnalyseData(AnalyseQueryModel analyseQueryModel) throws Exception{
        String fxlx = analyseQueryModel.getFxlx();
        if(ConstAnalyseType.CONST_ZBQFX.equals(fxlx)){
            List<ZbqfxCollect> zbqfxCollects = new LinkedList<>();
            ZbqfxCollect zbqfxCollect = new ZbqfxCollect();
            List<ZbqfxTjxx> zbqfxTjxx = sticZbqfxMapper.getZbqfxTjxx(analyseQueryModel.getFxbs());
            zbqfxCollect.setTjxx(zbqfxTjxx);
            zbqfxCollects.add(zbqfxCollect);
            return zbqfxCollects;
        }else if(ConstAnalyseType.CONST_CSZBYJJBNTFX.equals(fxlx)){
            List<CszbYjjbntCollect> cszbYjjbntCollects = new LinkedList<>();
            List<YjjbntTjxx> yjjbntTjxxes = sticCszbYjjbntMapper.selectYjjbntTjxx(analyseQueryModel.getFxbs());
            for(YjjbntTjxx y : yjjbntTjxxes){
                Field[] fs = y.getClass().getDeclaredFields();
                for(Field f : fs){
                    f.setAccessible(true);//设置属性可以访问
                    Object val = f.get(y);
                    if(val instanceof String){
                        System.out.println(f.getType()+"\t是String");
                        if(((String) val).startsWith(".")){
                            f.set(y,"0"+val);
                        }
                    }
                }
            }
            List<YjjbntXxxx> yjjbntXxxxes = sticCszbYjjbntMapper.selectYjjbntXxxx(analyseQueryModel.getFxbs());
            for(YjjbntXxxx y : yjjbntXxxxes){
                Field[] fs = y.getClass().getDeclaredFields();
                for(Field f : fs){
                    f.setAccessible(true);//设置属性可以访问
                    Object val = f.get(y);
                    if(val instanceof String){
                        System.out.println(f.getType()+"\t是String");
                        if(((String) val).startsWith(".")){
                            f.set(y,"0"+val);
                        }
                    }
                }
            }
            CszbYjjbntCollect cszbYjjbntCollect = new CszbYjjbntCollect();
            cszbYjjbntCollect.setTjxx(yjjbntTjxxes);
            cszbYjjbntCollect.setXxxx(yjjbntXxxxes);
            cszbYjjbntCollects.add(cszbYjjbntCollect);
            return cszbYjjbntCollects;
        }else if(ConstAnalyseType.CONST_TZHDLGDFX.equals(fxlx)){
            List<TzhdlgdCollect> tzhdlgdCollects=new LinkedList<>();
            List<TzhdlgdfxTjxx> tzhdlgdfxTjxxes = sticTzhdlgdMapper.getTzhdlgdfxTjxxes(analyseQueryModel.getFxbs());
            List<TzhdlgdfxXxxx> tzhdlgdfxXxxxes = sticTzhdlgdMapper.getTzhdlgdXxxxes(analyseQueryModel.getFxbs());
            TzhdlgdCollect tzhdlgdCollect = new TzhdlgdCollect();
            tzhdlgdCollect.setTjxx(tzhdlgdfxTjxxes);
            tzhdlgdCollect.setXxxx(tzhdlgdfxXxxxes);
            tzhdlgdCollects.add(tzhdlgdCollect);
            return tzhdlgdCollects;
        } else{
            throw new Exception("目前还未提供此分析的结果");
        }
    }
}
